// phpFTPMakePath(dirPath, host, user, password)
//
// Create the path to the last directory specified in dirPath on a FTP server. Requires SmartPill PHP plugin.
//
// Returns:
//		 0		Successful
//		-1		Couldn't log in to the FTP server
//		-2		Couldn't create the directory(s)
//
Let (
	[
		$dirPath = dirPath ;
		$host = host ;
		$user = user ;
		$password = password ;

		phpCode = "error_reporting(0); //(E_ALL & ~E_NOTICE);¶
		¶
		$dirPath = fm_evaluate('$dirPath');¶
		$host = fm_evaluate('$host');¶
		$user = fm_evaluate('$user');¶
		$password = fm_evaluate('$password');¶
		¶
		$retVal = 0;¶
		$connection = ftp_connect($host);¶
		¶
		$login_result = @ftp_login($connection, $user, $password);¶
		if ((!$connection) || (!$login_result))¶
		{¶
			$retVal = -1;¶
		}¶
		else¶
		{¶
			ftp_pasv($connection, true);¶
			¶
			if (!MyFTPMakeDirRecursive($connection, $dirPath))¶
			{¶
				$retVal = -2;¶
			}¶
			¶
			ftp_close($connection);¶
		}¶
		¶
		¶
		function MyFTPMakeDirRecursive($connection, $path)¶
		{¶
			$dir = explode('/', $path);¶
			$path = '/';¶
			$ret = true;¶
			¶
			for ($i=1; $i < count($dir); $i++)¶
			{¶
				$path .= '/' . $dir[$i];¶
				if(!@ftp_chdir($connection, $path))¶
				{¶
					@ftp_chdir($connection, '/');¶
					if (!@ftp_mkdir($connection, $path))¶
					{¶
						$ret = false;¶
						break;¶
					}¶
				} ¶
			}¶
			return $ret;¶
		}¶
		¶
		echo $retVal;¶
		"
	] ;
	PHP_Execute(phpCode)
)